/*
The MIT License

Copyright (c) 2010 Guillaume Florimond (www.valhalla.fr)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
 */

/*
 * MessageFrame.java
 *
 * Created on 18 mars 2010, 18:21:19
 */

package fr.valhalla.vcrypt.ui;

import java.awt.Color;
import javax.swing.JMenuItem;
import javax.swing.text.DefaultEditorKit;

/**
 * MessageFrame
 * Displays a clear/crypted message.
 * Must be instanciated from ToolFrame class
 * @author Guillaume Florimond < gf@valhalla.fr > < www.valhalla.fr >
 */
public class MessageFrame extends javax.swing.JFrame {

    /** Creates new form MessageFrame */
    public MessageFrame() {
        initComponents();
    }

    public void setStatusCrypted(){
        this.messageLabel.setText("[Message chiffré]");
        this.labelPane.setBackground(Color.red);
        this.messageArea.setForeground(new Color(190,40,50));
    }

    public void setStatusDecrypted(){
        this.messageLabel.setText("[Message déchiffré]");
        this.labelPane.setBackground(Color.green);
        this.messageArea.setForeground(new Color(40,90,30));
    }

    public void setLabelInitial(){
        this.messageLabel.setText("[Message d'origine]");
    }

    public void setTextEditable(boolean b) {
        this.messageArea.setEditable(b);
        this.menuitem_editable.setState(b);

    }

    public String getMessage(){
        return this.messageArea.getText();
    }

    public void setMessage(String msg){
        this.messageArea.setText(msg);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        messagePane = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        messageArea = new javax.swing.JTextPane();
        labelPane = new javax.swing.JPanel();
        messageLabel = new javax.swing.JLabel();
        menubar = new javax.swing.JMenuBar();
        menu_file = new javax.swing.JMenu();
        menuitem_quit = new javax.swing.JMenuItem();
        menu_edit = new javax.swing.JMenu();
        menuitem_editable = new javax.swing.JCheckBoxMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        menuitem_copy = new JMenuItem(new DefaultEditorKit.CopyAction());
        menuitem_copyselection = new JMenuItem(new DefaultEditorKit.CopyAction());
        menuitem_paste = new JMenuItem(new DefaultEditorKit.PasteAction());
        menuitem_cut = new JMenuItem(new DefaultEditorKit.CutAction());

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        messagePane.setLayout(new java.awt.BorderLayout());

        messageArea.setBackground(new java.awt.Color(255, 255, 204));
        messageArea.setPreferredSize(new java.awt.Dimension(6, 200));
        jScrollPane1.setViewportView(messageArea);

        messagePane.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        getContentPane().add(messagePane, java.awt.BorderLayout.CENTER);

        labelPane.setBackground(new java.awt.Color(153, 153, 153));
        labelPane.setLayout(new java.awt.BorderLayout());

        messageLabel.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        messageLabel.setForeground(new java.awt.Color(255, 255, 255));
        messageLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        messageLabel.setText("Entrez votre message...");
        messageLabel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        labelPane.add(messageLabel, java.awt.BorderLayout.PAGE_START);

        getContentPane().add(labelPane, java.awt.BorderLayout.PAGE_START);

        menubar.setBackground(new java.awt.Color(255, 255, 204));
        menubar.setBorder(null);
        menubar.setForeground(new java.awt.Color(255, 255, 255));
        menubar.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

        menu_file.setText("Fichier");

        menuitem_quit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
        menuitem_quit.setText("Quitter");
        menuitem_quit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuitem_quitActionPerformed(evt);
            }
        });
        menu_file.add(menuitem_quit);

        menubar.add(menu_file);

        menu_edit.setText("Édition");

        menuitem_editable.setSelected(true);
        menuitem_editable.setText("Texte Modifiable");
        menuitem_editable.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuitem_editableActionPerformed(evt);
            }
        });
        menu_edit.add(menuitem_editable);
        menu_edit.add(jSeparator1);

        menuitem_copy.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        menuitem_copy.setText("Copier tout");
        menuitem_copy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuitem_copyActionPerformed(evt);
            }
        });
        menu_edit.add(menuitem_copy);

        menuitem_copyselection.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        menuitem_copyselection.setText("Copier la sélection");
        menu_edit.add(menuitem_copyselection);

        menuitem_paste.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
        menuitem_paste.setText("Coller");
        menuitem_paste.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuitem_pasteActionPerformed(evt);
            }
        });
        menu_edit.add(menuitem_paste);

        menuitem_cut.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        menuitem_cut.setText("Couper");
        menu_edit.add(menuitem_cut);

        menubar.add(menu_edit);

        setJMenuBar(menubar);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void menuitem_quitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuitem_quitActionPerformed
        System.exit(0);
    }//GEN-LAST:event_menuitem_quitActionPerformed

    private void menuitem_copyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuitem_copyActionPerformed
        this.messageArea.selectAll();
    }//GEN-LAST:event_menuitem_copyActionPerformed

    private void menuitem_pasteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuitem_pasteActionPerformed

    }//GEN-LAST:event_menuitem_pasteActionPerformed

    private void menuitem_editableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuitem_editableActionPerformed
        if(menuitem_editable.getState() == true)
            this.messageArea.setEditable(true);
        else
            this.messageArea.setEditable(false);
    }//GEN-LAST:event_menuitem_editableActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MessageFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JPanel labelPane;
    private javax.swing.JMenu menu_edit;
    private javax.swing.JMenu menu_file;
    private javax.swing.JMenuBar menubar;
    private javax.swing.JMenuItem menuitem_copy;
    private javax.swing.JMenuItem menuitem_copyselection;
    private javax.swing.JMenuItem menuitem_cut;
    private javax.swing.JCheckBoxMenuItem menuitem_editable;
    private javax.swing.JMenuItem menuitem_paste;
    private javax.swing.JMenuItem menuitem_quit;
    private javax.swing.JTextPane messageArea;
    private javax.swing.JLabel messageLabel;
    private javax.swing.JPanel messagePane;
    // End of variables declaration//GEN-END:variables

}
